<!DOCTYPE html>
<html data-use-rem>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/plan/caigou/css/cglist.css"/>
    <link rel="stylesheet" type="text/css" href="/plan/caigou/css/product.css"/>
    <link rel="stylesheet" type="text/css" href="/plan/caigou/css/add.css"/>
    <link rel="stylesheet" type="text/css" href="/plan/caigou/css/product_cate.css"/>

    <script type="text/javascript" src="/plan/caigou/js/jquery.1.9.1.js" ></script>
    <script type="text/javascript" src="/plan/caigou/js/layer.js" ></script>
    <link rel="stylesheet" type="text/css" href="/plan/caigou/css/layer.css"/>
    <script type="text/javascript" src="/plan/caigou/js/iScroll.js" ></script>
    <script type="text/javascript" src="/plan/caigou/js/Mdate.js" ></script>
    <link rel="stylesheet" href="/plan/caigou/css/Mdate.css" />
    <script type="text/javascript" src="/plan/caigou/js/rem.js" ></script>
    <script src="/plan/js/dropload.min.js"></script>
    <title>新增要货单</title>
</head>
<style>
    body{font-size:16px;position: relative}
    *{
        -webkit-overflow-scrolling: touch;
    }
    section{  margin:0;
        padding:0;
        border:0;
        outline:0;
        font-size:100%;
        vertical-align:baseline;
        background:transparent;
    }
    .session2{display: inline-block;margin-top: 0.1rem;font-size: 0.3rem;}
    #add1 ul,li,span,input,div{box-sizing: border-box}
    .caigou{font-size: 0.3rem;}
    .bitian0{margin-right: 0.2rem;}
    .bitian,.bitian2,.bitian3,.bitian0{float: right;color: #999;margin-top: 0.13rem;}

    input{-webkit-appearance: none;}
    body .layui-m-layer .layui-m-layer-msg{bottom: 0;}


    .z_button{
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;

    }
    .z_button div{width: 50%;float: left;
        background-color: #ffffff;
        height: 0.98rem;
        color: #4876b2;
        text-align: center;
        line-height: 0.98rem;

    }
    #zbtn2{
        background-color: #4876b2;
        color: #ffffff;
    }
    .dropload-noData,.dropload-load,.dropload-refresh{
        position: relative;
        margin-top: 0.31rem;
        font-size: 0.22rem;
        width: 1.6rem;
        margin: 0 auto;
        color: grey;
        text-align: center;
    }
    .dropload-noData:after,.dropload-load:after,.dropload-refresh:after {
        content: "";
        position: absolute;
        top: 0.16rem;
        width: 1.01rem;
        height: 1px;
        background-color: #eeeeee;
        right: -1.18rem;
    }

    .dropload-noData:before,.dropload-load:before,.dropload-refresh:before {
        content: "";
        position: absolute;
        top: 0.16rem;
        width: 1.01rem;
        height: 1px;
        background-color: #eeeeee;
        left: -1.2rem;
    }
    .dropload-down{
        display: none;
    }

    .productinfo{margin: 0 0 0.2rem 0;}
    .infop2{font-size: 0.28rem;margin: 0.1rem 0;}
    .session{font-size: 0.3rem;margin-top: 0.1rem;display: inline-block;}
    .znum{width:0.8rem}
    #add1{display: block}
    #add2{display: none}
    #add3{display: none}
    #add4{display: none}
    #add5{display: none}
    .lastleft{width: 100%;border:none}
</style>
<body>
<section id="add1" style="display: block">
    <form id="form2" action="" enctype="multipart/form-data"  method="post">
        <ul class="order_money" style="padding: 0 0.3rem;background: #fff;">
            <li>
                <span class="num" style="text-align: left">编号</span>
                <span class="bitian0">必填</span>
                <input type="text" name="" id="week" readonly value="{$bh}">
            </li>
            <li id="dateShowBtn">
                <span class="time">单据日期</span>
                <span class="jt"></span>
                <span class="bitian">必填</span>
                <input type="text" disabled="disabled" name="" id="dateShowOne" value="{:date("Y-m-d")}" />
            </li>
            <li class="caigou">
                <span class="cg">仓库名称</span>
                <span class="caigou">{$gname}</span>
            </li>

            <li class="caigou">
                <span class="cg">仓管人员</span>
                <span class="caigou">{$username}</span>
            </li>
        </ul>
        <ul class="product">
            <li>产品信息<div class="jia"><img src="/plan/caigou/img/jia.png"/></div></li></a>
        </ul>
        <ul class="productinfo" style="margin-top: 0" id="pro1">


            <li>
                <div class="lastleft">
                    <p>0</p>
                    <p>数量合计</p>
                </div>
                <div class="lastright">
                    <p class="infop3">¥0</p>
                    <p>金额合计</p>
                </div>
            </li>
        </ul>
        <ul class="beizhu">

            <li style="height: 2.5rem;">
                <p class="title">单据备注</p>
                <textarea name="" value="" id="mark" ></textarea>
            </li>
        </ul>
        <div class="z_button">
            <div id="zbtn1">保存草稿</div>
            <div id="zbtn2">提交审批</div>
        </div>

    </form>
</section>

<section id="add2" style="position:relative">
    <div class="top">
        <div class="top_left">
            <span class="top_left_con1">产品分类</span>
            <img class="top_left_xia1" src="/plan/caigou/img/jtxia.png" />
            <img class="top_left_up1" src="/plan/caigou/img/jtup.png" />
        </div>
        <div class="sou"></div>
        <div class="cate_mid">
            <div class="text_box" name="list_search_text_box" onclick="">
                <input id="keyword" name="search" type="text" placeholder="搜索" class="text" value="">
                <input type="button" value="" class="submit" id="list_search_submit">
                <div class="close" id="close2">取消</div>
            </div>
        </div>
    </div>

    <ul class="productinfo" id="pro2" style="margin-top: 1rem">


    </ul>
    <div class="footer">
        <img src="/plan/caigou/img/xuan.png"/>
        <span style="float: left;">已选：<span class="xuannum">0</span>项</span>
    </div>
    <div class="queding">确定</div>
</section>
<section id="add3">
    <form id="form2" action="" enctype="multipart/form-data"  method="post">
        <ul class="productinfo">
            <li>
                <div class="infoleft"><img src="/plan/caigou/img/product.png"/></div>
                <div class="inforight">
                    <p id="title3"></p>
                    <p class="infop2" id="bh3"></p>
                    <p class="infop3" id="store3">库存:</p>
                </div>
            </li>
        </ul>
        <ul class="order_money" style="padding: 0 0.3rem;background: #fff;">

            <li>
                <span class="address">数量</span>
                <span class="bitian">必填</span>

                <input type="number" id="num3" onkeyup="this.value.replace(/\D/g,'')"  placeholder="请输入数量"></input>
            </li>
            <li style="display: none">
                <span class="num" style="text-align: left">采购单价</span>
                <input type="number" id="week3"  onkeyup="this.value.replace(/(\D|^\.?)/g,'')" placeholder="0" value=""></input>
            </li>

        </ul>
        <div class="button">
            <div class="close" id="del3" style="margin-left: 0">删除</div>
            <div class="continue" id="btn3">保存<!--<input class="pay" type="submit" name="" id="" value="保存" />--></div>
        </div>
    </form>
</section>
<section id="add5" style="display: none">
    <div id="mescroll" class="mescroll" style="top:0.03rem" >
        <ul class="cglist" id="cglist" style="margin-bottom: 1rem; ">
        </ul>
    </div>
</section>
<section id="add6" style="display: none">
    <div class="container">
        <ul class="catetop">
            <li class="catetop_left" data-id="1"><span class="show">半成品</span></li>
            <li class="catetop_right"  data-id="2"><span>成品</span></li>
        </ul>
        <div class="goods">
            <div class="left_tab_container">
                <ul class="category">
                    {volist name="preCate" id="vo"}
                    <li {if condition="$i eq 1"}class="cateshow"{/if} dataid="{$vo.id}">{$vo.name}</li>
                    {/volist}
                </ul>
            </div>
            <ul class="cate_content">
                <li id="cate_ajax">

                    {volist name="cate" id="vo"}
                    <div class="cate_content_title">
                        <span class="h"></span><span>{$vo.name}</span><span class="h"></span>
                    </div>
                    <table cellspacing="0" cellpadding="0">
                        <tr>
                            {volist name="vo['cateArr']" id="v"}
                            <td onclick="tdClick(this)" dataid="{$v.id}">{$v.name}</td>
                            {/volist}
                        </tr>
                    </table>
                    {/volist}



                </li>

            </ul>
        </div>

    </div>
</section>

<script>//提交表单
var jsonData={};
jsonData.cate1 = {$preCate[0]['id']};//默认第一个分类
jsonData.type=1;
var listPage;
var meLoad;
var cgMeLoad;
var prev=$(".company").children(":first")
var preProduct;//控制产品价格
var tempList=[];
var tab;
var scrollTemp=0;//滚动到指定位置
$(function(){
    //测试部分
    /*第一步初始化*/
    //clearCache()
    initProduct();
    document.getElementById("zbtn1").addEventListener("click",clickHandle);
    document.getElementById("zbtn2").addEventListener("click",clickHandle);
    $(".catetop li").click(function () {
        let _this = $(this);
        let did = _this.attr('data-id');
        if (jsonData.type==did)return false;
        $(".catetop li").find('span').removeClass('show');
        _this.find('span').addClass('show');
        jsonData.type=did;
        jsonData.times = Math.random()*10;
        layer.open({type: 2,  shadeClose: false});
        $.ajax({
            type:"get",
            data:jsonData,
            url:"/index/fgs/getCate1",
            success:function (data) {
                layer.closeAll();
                let datas = data.list;
                let str='';
                datas.forEach(function (e,i) {
                    if (i==0) {
                        str+='<li class="cateshow" dataid="'+e.id+'">'+e.name+'</li>';
                    }else{
                        str+='<li  dataid="'+e.id+'">'+e.name+'</li>';
                    }
                })
                $("#cate1").html(str);
                $("#cate_ajax").html(data.html);
            }
        });
    });
    $(".category li").click(function () {
        let _this = $(this);
        let did = _this.attr('dataid');

        if (did==jsonData.cate1)return false;
        let preCate = jsonData.cate1;
        jsonData.cate1=did;
        layer.open({type: 2,  shadeClose: false});

        $.ajax({
            type:"post",
            data:jsonData,
            url:"/index/fgs/getCate1",
            success:function (data) {

                layer.closeAll();
                if (data.code==0){
                    jsonData.cate1=preCate;
                    layer.open({
                        content:'此分类下暂无分类' ,
                        skin: 'msg',
                        time: 2 //2秒后自动关闭
                    });
                    return false;
                }else{
                    $(".category li").removeClass('cateshow');
                    _this.addClass('cateshow');
                    $("#cate_ajax").html(data.html);
                }
            }
        });

    });
    $(".danhao").click(function () {
        $("#add1").hide();
        $("#add5").show();

        if(listPage===undefined || listPage==null){
            listPage=1;
            overCglist();

        }
    })
    $(".cglist").on("click",".closePay",function () {
        $("#add5").hide()
        $("#add1").show()
    });
    $(".supplier").click(function () {
        $("#add1").hide();

        $("#add4").show();
    });
    $("#sup  li").click(function () {
        var _this = $(this);
        $("#add4").hide();
        $("#add1").show();
        let datas = JSON.parse(_this.attr("databind"));
        if (datas.id==$("#supval").val()){
            return false;
        }

        $("#danhao").html('');
        tempList=[];
        listPage=null;
        $("#cglist").html('');
        $("#cid").val(0);
        updateList(tempList);
        $("#supname").html(datas.name);
        $("#supval").val(datas.id);


    });
    //第三部保存
    $("#btn3").click(function () {
        let num3= parseInt($("#num3").val());
        let week3=parseFloat($("#week3").val());
        if (num3 < 1 || isNaN(num3)){
            layer.open({
                content:'商品数量必填' ,
                skin: 'msg',
                time: 2 //2秒后自动关闭
            });
            return false;
        }

        if (tab==null){
            let tempVal = $(preProduct).val();
            let data = JSON.parse($(preProduct).attr("bindttr"));
            if (num3 > data.storenum){
                layer.open({
                    content:'数量不能大于库存数量' ,
                    skin: 'msg',
                    time: 2 //2秒后自动关闭
                });
                return false;
            }
            //如果之前在外层显示上没有累计1
            if (tempVal < 1){
                let num = parseInt($(".xuannum").html());
                $(".xuannum").html(num+1);
            }
            $(preProduct).val(num3);
            $("html,body").animate({scrollTop:scrollTemp});
            $(preProduct).attr("price",week3);
            $("#add2").show();
            $("#add3").hide();
        } else{


            let id=tempList[tab].id;
            if (tempList[tab].hasOwnProperty("actual")) {
                if (num3 > tempList[tab].actual){
                    layer.open({
                        content:'数量不能大于入库数量' ,
                        skin: 'msg',
                        time: 2 //2秒后自动关闭
                    });
                    return false;
                }
            }else{
                if (num3 > tempList[tab].storenum){
                    layer.open({
                        content:'数量不能大于库存数量' ,
                        skin: 'msg',
                        time: 2 //2秒后自动关闭
                    });
                    return false;
                }
            }
            tempList[tab].number=num3;
            tempList[tab].price=parseFloat(week3);
            $("#zt"+id).val(num3);
            $("#zt"+id).attr("price",parseFloat(week3));
            updateList(tempList);
            $("#add1").show();
            $("#add3").hide();
        }

    });
    $("#del3").click(function () {
        if (tab==null){
            let tempVal = $(preProduct).val();
            if (tempVal > 0){
                let num = parseInt($(".xuannum").html());
                $(".xuannum").html(num-1);
            }
            //删除自身身上数量
            $(preProduct).val('');
            $(preProduct).removeAttr('price');
            $("#add2").show();
            $("#add3").hide();
        } else{
            let id = tempList[tab].id;

            removeObj(tab);

            $("#zt"+id).val('');
            $("#zt"+id).attr('');

            updateList(tempList);
            $("#add1").show();
            $("#add3").hide();
        }

    });

    //搜索部分
    $("#list_search_submit").click(function () {
        let seVal = $("#keyword").val();
        if (seVal==''){
            layer.open({
                content:'关键词不能为空' ,
                skin: 'msg',
                time: 2 //2秒后自动关闭
            });
        }
        //清空Pid属性
        if (jsonData.hasOwnProperty("pid"))delete jsonData.pid;
        jsonData.counter=1;
        jsonData.title=seVal;
        //分类搜索重置
        $(prev).css("color",'#333');
        $(".company").children(":first").css('color','#457bc7');
        prev=$(".company").children(":first");
        overProduct();


    });


    $(".jia").click(function () {
        $("#add1").hide();
        $("#add2").show();
        //如果不是第一次打开
        if (jsonData.hasOwnProperty("counter")===false){
            jsonData.counter=1;
            productData();
        }
        meLoad.unlock();
        if (tempList){
            $(".xuannum").html(tempList.length);
        }
        $("html,body").animate({scrollTop:scrollTemp});

    });
    $('.top_left').click(function(){

        //$("#pro2").html('');

        $("#add6").toggle();

        $("#pro2").toggle();
        $("#add2 .footer").toggle();
        $("#add2 .queding").toggle();

        $('.top_left_con1').css('color','#000');

    });
    $('.sou').click(function(){
        $('.cate_mid').show();
        $('.company').hide();
        $('.top_left_up1').hide();
        $('.top_left_xia1').show();
        $('.top_left_con1').css('color','#555');
    });
    $('#close2').click(function(){
        //清空带有搜索的选项
        if (jsonData.hasOwnProperty("title")) {
            jsonData.counter=1;
            delete jsonData.title;
            overProduct();

        }
        $('.cate_mid').hide();
    });
    $(".company").on("click","li",function (e,i) {
        jsonData.counter=1;
        if ($(this).index()==0){
            //删除自身属性
            if (jsonData.hasOwnProperty("pid"))delete jsonData.pid;
        }
        if ($(this).index()!=0)jsonData.pid=$(this).attr("dataid");
        $(prev).css("color",'#333');
        $(this).css('color','#457bc7');
        prev=this;
        $('.company').toggle();
        $('.top_left_xia1').toggle();
        $('.top_left_up1').toggle();
        $("#pro2").html('');
        overProduct();
    });
    //确定保存部分
    $(".queding").click(function () {
        let tempObj=[];
        $(".znum").each(function (i,e) {

            if(e.value > 0){
                let temp=JSON.parse($(this).attr("bindttr"));
                temp.number=parseInt(e.value);
                if($(e).attr("price") > 0){
                    temp.price=parseFloat($(e).attr("price"));

                }
                tempObj.push(temp);
            }
        });

        if (tempList==false && tempObj.length < 1){
            layer.open({
                content:'暂未选择任何商品' ,
                skin: 'msg',
                time: 2 //2秒后自动关闭
            });
            return false;
        }

        //检测未显示出的HTML
        if (tempList) {
            tempList.forEach(function (e) {
                if ($("#zt" + e.id).length == 0) {
                    tempObj.push(e)
                }
            })
        }

        tempList=tempObj;
        if (tempList.length < 1){
            layer.open({
                content:'暂未选择任何商品' ,
                skin: 'msg',
                time: 2 //2秒后自动关闭
            });
            return false;
        }
        updateList(tempObj);
        meLoad.lock();
        $("#add2").hide();
        $("#add1").show();
        //setCahce(obj);

    });
});
function tdClick(obj) {
    let did = $(obj).attr('dataid');
    if (jsonData.hasOwnProperty("pid") && jsonData.pid==did){
        $("#add6").hide();
        $("#pro2").show();
        return false;
    }

    jsonData.counter=1;
    $("#cate_ajax td").css("color",'#808080');
    jsonData.pid=did;
    $(obj).css("color",'#ffa400');

    $("#pro2").html('');
    $("#add6").hide();
    $("#add2 .footer").show();
    $("#add2 .queding").show();
    $("#pro2").show();
    overProduct();

}


function clickHandle(e) {
    if ($("#zbtn1").hasClass("disabled") || $("#zbtn2").hasClass("disabled")) return false;
    let obj = checkForm()
    if (!obj)return false;
    if (e.target.id=="zbtn1") {
        obj.status=10;//草稿
    }else{
        obj.status=9;//提交审批
    }
    $("#zbtn1").addClass("disabled");
    $("#zbtn2").addClass("disabled");
    layer.open({type: 2,  shadeClose: false});
    $.ajax({
        type:"post",
        url:"inStore",
        data:obj,
        success:function (data) {
            layer.closeAll()
            if (data.code==1){
                layer.open({
                    content:'添加成功' ,
                    skin: 'msg',
                    time: 2 //2秒后自动关闭
                });
                setTimeout(function () {
                    location.href="/index/fgs/index";
                },600);
            } else{
                layer.open({
                    content:'添加失败' ,
                    skin: 'msg',
                    time: 2 //2秒后自动关闭
                });
                setTimeout(function () {
                    location.reload();
                },500);
            }

        }

    })

}
function checkForm() {

    if ($("#dateShowOne").val()==''){
        layer.open({
            content:'单据日期必填' ,
            skin: 'msg',
            time: 2 //2秒后自动关闭
        });
        return false;
    }
    let bool=false;
    //检测产品信息
    let shopList=[];

    if (tempList.length < 1 || tempList==false){
        layer.open({
            content:'必须选择商品！' ,
            skin: 'msg',
            time: 2 //2秒后自动关闭
        });
        return false;
    }
    for (let i in tempList){
        let tempObj = tempList[i];

        let tempArr={"id":tempObj.id,"num":tempObj.number,"price":tempObj.price};
        shopList.push(tempArr)

    }



    let obj={};
    obj.riqi=$("#dateShowOne").val();
    obj.shopList=shopList;
    obj.order_id=$("#week").val();

    obj.mark=$("#mark").val();
    obj.sub=1;



    return obj;
}
//clearCache()
function initProduct() {
    tempList = [];
    updateList(tempList);

}
//删除对象的某一项
function removeObj(tab) {
    let tempObj=[];

    tempList.forEach(function (e,i) {
        if (i!=tab){
            tempObj.push(e);
        }
    });
    tempList=tempObj;

}
//更新产品List
function updateList(obj){

    if (obj.length > 0){

        let str='';
        let price=0,num=0;

        obj.forEach(function (e,i) {
            if (e.hasOwnProperty("price") && e.price!=null && e.price!=0 && !isNaN(e.price)){

                let tP = parseFloat(e.price).toFixed(2);
                price+=e.number*tP;
                //存在价格
                str+='<li onclick="checkPrice(1,'+i+')">\n' +
                    '\t\t<div class="infoleft"><img src="/plan/caigou/img/product.png"></div>\n' +
                    '\t\t<div class="inforight">\n' +
                    '\t\t\t<p>'+e.cname+'</p>\n' +
                    '\t\t\t<p class="infop2">仓库：北京仓库</p>\n' +
                    '\t\t\t<p class="infop3">'+e.number+'本</p>\n' +
                    '\t\t</div>\n' +
                    '\t</li>';
            } else{
                str+='<li onclick="checkPrice(1,'+i+')">\n' +
                    '\t\t<div class="infoleft"><img src="/plan/caigou/img/product.png"></div>\n' +
                    '\t\t<div class="inforight">\n' +
                    '\t\t\t<p>'+e.cname+'</p>\n' +
                    '\t\t\t<p class="infop2">仓库：北京仓库</p>\n' +
                    '\t\t\t<p class="infop3">'+e.number+'本</p>\n' +
                    '\t\t</div>\n' +
                    '\t</li>';

            }
            num+=e.number;
        })
        let lastLi = '<li>\n' +
            '            <div class="lastleft">\n' +
            '                <p>'+num+'</p>\n' +
            '                <p>数量合计</p>\n' +
            '            </div>\n' +
            '        </li>';
        str+=lastLi;
        $("#pro1").html(str);
    }else{
        let lastLi = '<li>\n' +
            '            <div class="lastleft">\n' +
            '                <p>0</p>\n' +
            '                <p>数量合计</p>\n' +
            '            </div>\n' +
            '        </li>';

        $("#pro1").html(lastLi);

    }
    return;
}
function clearCache() {
    localStorage.clear("productList");
}
function setCahce(obj) {
    if (obj.length < 1)return false;
    localStorage.setItem("productList",JSON.stringify(obj));
}
function getCache(){
    var data = JSON.parse(localStorage.getItem("productList"));
    if (data==null){
        return false;
    }
    return data;

}
//价格添加
function checkPrice(obj,...args) {
    let arg = args;
    if (arg.length > 0){

        tab=arg[0];

        $("#title3").html(tempList[tab].cname);
        $("#bh3").html(tempList[tab].b_n);
        $("#store3").html("库存"+tempList[tab].storenum);
        //检测当前数量和价格
        $("#num3").val(tempList[tab].number);

        $("#week3").val(tempList[tab].price)

        $("#add1").hide();
        $("#add3").show();
    } else{
        tab=null;
        //找到父节点li，找到当前是否存在数量
        preProduct = obj.lastElementChild.lastElementChild.lastElementChild.children[1].lastElementChild;
        scrollTemp = $(document).scrollTop();
        let temp = JSON.parse($(preProduct).attr("bindttr"));
        $("#title3").html(temp.cname);
        $("#bh3").html(temp.b_n);
        $("#store3").html("库存"+temp.storenum);
        //检测当前数量和价格
        let tempPrice='';

        $("#add2").hide();
        $("#num3").val($(preProduct).val());
        $("#week3").val($(preProduct).attr("price"))
        $("#add3").show();
    }

}
//检测是否存在，并返回数组

function checkInArray(arr) {

    if (tempList){
        let temp=false;
        for(let i in tempList){
            if(tempList[i].id==arr.id){
                temp=tempList[i];
                break;
            }
        }
        return temp;
    }
    return false;
}
function getList(data) {
    var str='';
    data.forEach(function (e,i) {

        let ch = checkInArray(e);

        if (ch){

            str+='<li>\n' +
                '\t\t\t\t<div class="infoleft" onclick="checkPrice(this.parentElement)"><img src="/plan/caigou/img/product.png"></div>\n' +
                '\t\t\t\t<div class="inforight">\n' +
                '\t\t\t\t\t<p  onclick="checkPrice(this.parentElement.parentElement)">'+e.cname+'</p>\n' +
                '\t\t\t\t\t<p class="infop2">'+e.b_n+'</p>\n' +
                '\t\t\t\t\t<div class="infop3">\n' +
                '\t\t\t\t\t\t库存:<span>'+e.storenum+'</span>\n' +
                '\t\t\t\t\t\t<!--<input class="info3_right" type="button" value="+" />-->\n' +
                '\t\t\t\t\t\t<div class="box">\n' +
                '\t\t\t\t\t\t\t<div>\n' +
                '\t\t\t\t\t\t\t\t<input class="cut" type="button"  onclick="reduceCart(this)" value="-">\n' +
                '\t\t\t\t\t\t\t</div>\n' +
                '\t\t\t\t\t\t\t<div>';
            str+=`<input class="num znum" id="zt${e.id}" top="this.offsetTop"  bindttr='{"id":${e.id},"b_n":"${e.b_n}","cname":"${e.cname}","storenum":${e.storenum}}' value="${ch.number}" price="${ch.price}" onkeyup="this.value.replace(/\D/g,'')"  type="number" name="number" placeholder="0">`
            str+='\t\t\t\t\t\t\t</div>\n' +
                '\t\t\t\t\t\t\t<div>\n' +
                '\t\t\t\t\t\t\t\t<input class="add" onclick="addCart(this,'+e.storenum+')" type="button" value="+">\n' +
                '\t\t\t\t\t\t\t</div>\n' +
                '\t\t\t\t\t  </div>\n' +
                '\t\t\t\t\t</div>\n' +
                '\t\t\t\t</div>\n' +
                '\t\t\t</li>';
        } else{
            str+='<li>\n' +
                '\t\t\t\t<div class="infoleft" onclick="checkPrice(this.parentElement)"><img src="/plan/caigou/img/product.png"></div>\n' +
                '\t\t\t\t<div class="inforight">\n' +
                '\t\t\t\t\t<p  onclick="checkPrice(this.parentElement.parentElement)">'+e.cname+'</p>\n' +
                '\t\t\t\t\t<p class="infop2">'+e.b_n+'</p>\n' +
                '\t\t\t\t\t<div class="infop3">\n' +
                '\t\t\t\t\t\t库存:<span>'+e.storenum+'</span>\n' +
                '\t\t\t\t\t\t<!--<input class="info3_right" type="button" value="+" />-->\n' +
                '\t\t\t\t\t\t<div class="box">\n' +
                '\t\t\t\t\t\t\t<div>\n' +
                '\t\t\t\t\t\t\t\t<input class="cut" type="button"  onclick="reduceCart(this)" value="-">\n' +
                '\t\t\t\t\t\t\t</div>\n' +
                '\t\t\t\t\t\t\t<div>';
            str+=`<input class="num znum" id="zt${e.id}"   bindttr='{"id":${e.id},"b_n":"${e.b_n}","cname":"${e.cname}","storenum":${e.storenum}}' value="${ch.number}" price="${ch.price}" onkeyup="this.value.replace(/\D/g,'')"  type="number" name="number" placeholder="0">`
            str+='\t\t\t\t\t\t\t</div>\n' +
                '\t\t\t\t\t\t\t<div>\n' +
                '\t\t\t\t\t\t\t\t<input class="add" onclick="addCart(this,'+e.storenum+')" type="button" value="+">\n' +
                '\t\t\t\t\t\t\t</div>\n' +
                '\t\t\t\t\t  </div>\n' +
                '\t\t\t\t\t</div>\n' +
                '\t\t\t\t</div>\n' +
                '\t\t\t</li>';
        }

    });
    return str;
}

//重载产品数据
function overProduct() {

    $.ajax({
        type:"post",
        url:"/index/fgs/getProduct",
        data:jsonData,
        success:function (data) {
            if (data.list!=null){
                jsonData.counter++;
                let str=getList(data.list);
                $("#pro2").html(str);
                $("#pro2").show();
                if (data.list.length!=6){
                    meLoad.lock();
                    // 无数据
                    meLoad.noData();
                }else{
                    meLoad.unlock();
                    meLoad.noData(false);
                    meLoad.resetload();
                }





            }

        }

    })
}
function productData() {

    $('.dropload-down').remove();

    // 每页展示4个
    var num = 6;
    var pageStart = 1,pageEnd = 0;


    // dropload
    meLoad =  $('#pro2').dropload({
        scrollArea : window,
        loadDownFn : function(me){

            $.ajax({
                type:"post",
                url:"/index/fgs/getProduct",
                data:jsonData,
                success:function (data) {

                    jsonData.counter++;
                    pageEnd = num * jsonData.counter;
                    pageStart = pageEnd - num;
                    if (data.list!=null){
                        if (data.list.length!=6){
                            me.lock();
                            // 无数据
                            me.noData();
                        }
                        let str=getList(data.list);
                        $("#pro2").append(str);
                        me.resetload();
                    }else{
                        me.lock();
                        // 无数据
                        me.noData();
                    }

                },
                error: function(xhr, type) {
                    me.lock();
                    // 无数据
                    me.noData();
                    me.resetload();
                }
            })

        }
    });


}
function reduceCart(obj){
    let objChild = $(obj).parent('div').next('div').find('input');
    let temp = parseInt(objChild.val());
    if (temp==1){
        let num = parseInt($(".xuannum").html());
        $(".xuannum").html(num-1);
    }
    if (temp==null || temp <=0)return;
    temp--;
    objChild.val(temp)
}
function addCart(obj,storenum) {

    let objChild = $(obj).parent('div').prev('div').find('input');
    let temp = parseInt(objChild.val());
    if (temp==null || temp<=0){
        let num = parseInt($(".xuannum").html());
        $(".xuannum").html(num+1);
    }
    if (isNaN(temp))temp=0;
    if(temp+1 > storenum){
        return false;
    }

    temp++;
    objChild.val(temp)

}
new Mdate("dateShowBtn", {
    //"dateShowBtn"为你点击触发Mdate的id，必填项
    acceptId: "dateShowOne",
    //此项为你要显示选择后的日期的input，不填写默认为上一行的"dateShowBtn"
    beginYear: "2010",
    //此项为Mdate的初始年份，不填写默认为2000
    beginMonth: "1",
    //此项为Mdate的初始月份，不填写默认为1
    beginDay: "1",
    //此项为Mdate的初始日期，不填写默认为1
    endYear: "2050",
    //此项为Mdate的结束年份，不填写默认为当年
    endMonth: "12",
    //此项为Mdate的结束月份，不填写默认为当月
    endDay: "31",
    //此项为Mdate的结束日期，不填写默认为当天
    format: "-"
    //此项为Mdate需要显示的格式，可填写"/"或"-"或".",不填写默认为年月日
})
</script>
</body>
</html>
